<?php

namespace app\service;

use app\exception\ErrnoPlus;
use app\model\OssAliyunPayedProductModel;
use share\exception\ApiException;
use share\service\BaseModelService;

class OssAliyunPayedProductService extends BaseModelService
{

    public static function getModel()
    {
        return new OssAliyunPayedProductModel;
    }

    /**
     * 编辑条目 新增或者修改
     */
    public static function edit($info)
    {
        $id = $info['id'];
        unset($info['id']);
        if ($id == 0) {
            self::addOssAliyunPayedProduct($info);
        } else {
            self::updateOssAliyunPayedProduct($id, $info);
        }
        //TODO add code here after data change
        return $info;
    }

    /**
     * 新增条目
     */
    public static function addOssAliyunPayedProduct($info)
    {
        //TODO add code here  
        self::add($info);
    }

    /**
     * 修改条目
     */
    public static function updateOssAliyunPayedProduct($id, $info)
    {
        $origin  = self::getBase($id);
        if (empty($origin)) {
            throw new ApiException("origin data is not exists", ErrnoPlus::COMMON_INVALID_INPUT);
        }
        //TODO  add code here  

        self::update($id, $info);
    }

    /**
     * 删除条目
     */
    public static function delById($id)
    {
        $origin = self::getBase($id);
        if (empty($origin)) {
            return;
        }
        //TODO  add code here  
        $res = self::del($id);
        return $res;
    }

    /**
     * 页面查询条件
     */
    public static function buildCondition($filter)
    {
        $res = [];
        if (isset($filter['name']) && !empty($filter['name'])) {
            $res['name'] = ['like', '%' . $filter['name'] . '%'];
        }
        if (isset($filter['type']) && !empty($filter['type'])) {
            $res['type'] = $filter['type'];
        }
        //TODO  add code here  
        return $res;
    }
}
